#region [file: PessoaJuridicaDAL.cs, author: Lucas Bittencourt]
// File:    PessoaJuridicaDAL.cs
// Author:  Lucas Bittencourt
// Created: sábado, 24 de dezembro de 2011 01:06:31
// Purpose: Defines dao implementation class for class PessoaJuridica
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IPessoaJuridicaDAL interface
   /// </summary>
   public class PessoaJuridicaDAL : NHibernateDALBase,  IPessoaJuridicaDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of PessoaJuridica
      /// </summary>     
      public List<PessoaJuridica> GetPessoaJuridicaList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(PessoaJuridica)));
      }
      
      /// <summary>
      /// Get the instances of PessoaJuridica from index firstResult to index maxResult
      /// </summary>
      public List<PessoaJuridica> GetPessoaJuridicaList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(PessoaJuridica), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of PessoaJuridica according its primary key instance.
      /// </summary>
      public PessoaJuridica Load(PessoaJuridicaPK pessoaJuridicaPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "PejIdPessoaJuridica" };
         object[] values = new object[] { pessoaJuridicaPK.PejIdPessoaJuridica };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(PessoaJuridica), cs);
         return (((list != null) && (list.Count > 0)) ? (PessoaJuridica)list[0] : null);
      }

      /// <summary>
      /// Query the instances of PessoaJuridica according its example instance.
      /// </summary>
      public List<PessoaJuridica> QueryByExample(PessoaJuridica pessoaJuridica)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(PessoaJuridica), pessoaJuridica));
      }

      /// <summary>
      /// Query the instances of PessoaJuridica according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<PessoaJuridica> QueryByExample(PessoaJuridica pessoaJuridica, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(PessoaJuridica), pessoaJuridica, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of PessoaJuridica
      /// </summary>
      public void Insert(PessoaJuridica pessoaJuridicaObject)
      {
         base.Save(pessoaJuridicaObject);
      }
      
      /// <summary>
      /// Update the instances of PessoaJuridica
      /// </summary>
      public void Update(PessoaJuridica pessoaJuridicaObject)
      {
         base.Update(pessoaJuridicaObject);
      }
      
      /// <summary>
      /// Delete the instances of PessoaJuridica
      /// </summary>
      public void Delete(PessoaJuridica pessoaJuridicaObject)
      {
         base.Delete(pessoaJuridicaObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNmRazaoSocial
      /// </summary>
      public List<PessoaJuridica> FindByPejNmRazaoSocial(string pejNmRazaoSocial) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNmRazaoSocial", pejNmRazaoSocial));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs));
      }
      
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNmRazaoSocial, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<PessoaJuridica> FindByPejNmRazaoSocial(string pejNmRazaoSocial, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNmRazaoSocial", pejNmRazaoSocial));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNuInscricaoEstadual
      /// </summary>
      public List<PessoaJuridica> FindByPejNuInscricaoEstadual(string pejNuInscricaoEstadual) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNuInscricaoEstadual", pejNuInscricaoEstadual));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs));
      }
      
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNuInscricaoEstadual, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<PessoaJuridica> FindByPejNuInscricaoEstadual(string pejNuInscricaoEstadual, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNuInscricaoEstadual", pejNuInscricaoEstadual));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNuInscricaoMunicipal
      /// </summary>
      public List<PessoaJuridica> FindByPejNuInscricaoMunicipal(string pejNuInscricaoMunicipal) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNuInscricaoMunicipal", pejNuInscricaoMunicipal));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs));
      }
      
      /// <summary>
      /// Find the instances of PessoaJuridica according to its attribute pejNuInscricaoMunicipal, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<PessoaJuridica> FindByPejNuInscricaoMunicipal(string pejNuInscricaoMunicipal, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("PejNuInscricaoMunicipal", pejNuInscricaoMunicipal));
         return ConvertToGenericList(base.FindByCriterions(typeof(PessoaJuridica), cs, firstResult, maxResult));
      }
      /// <summary>
      /// Find <Code>PessoaJuridica</Code> instances by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <returns>PessoaJuridica instance list</returns>
      public List<PessoaJuridica> FindByPessoa(Pessoa pessoa)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs));
      }
      
      
      /// <summary>
      /// Find <Code>PessoaJuridica</Code> instances  instances in range firstResult, maxResult by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>PessoaJuridica instance list</returns>
      public List<PessoaJuridica> FindByPessoa(Pessoa pessoa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));}

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<PessoaJuridica> ConvertToGenericList(IList pessoaJuridicas)
      {
         List<PessoaJuridica> pessoaJuridicaList = new List<PessoaJuridica>();
         foreach (PessoaJuridica pessoaJuridica in pessoaJuridicas)
         {
             pessoaJuridicaList.Add(pessoaJuridica);
         }
         return pessoaJuridicaList;
      }      
   }
}